import tensorflow as tf
import sys
sys.path.append("./")
import numpy as np
import time
import pandas as pd
import model_zoo.utils as utils
import cv2
import pickle

layer_name_list = ["input", "Conv2d_1a_3x3", "Conv2d_2a_3x3", "Conv2d_2b_3x3",
                   "MaxPool_3a_3x3", "Conv2d_3b_1x1", "Conv2d_4a_3x3",
                   "MaxPool_5a_3x3", "Mixed_5b", "Mixed_5c",
                   "Mixed_5d", "Mixed_6a", "Mixed_6b", "Mixed_6c",
                   "Mixed_6d", "Mixed_6e", "Mixed_7a",
                   "Mixed_7b", "Mixed_7c"]
model_name = "inception_v3"
# 1. read the data
time_dict = {}
layer_details = []
for layer_name in layer_name_list[1:]:
    file_name = "./middle_data/" + model_name + "/"+layer_name+"_guitar" + ".npy"
    input_data = np.asarray(np.load(file_name), dtype=np.float32)#[np.newaxis,:]
    time_cost = []
    for i in range(200):
        a = time.time()
        min_range = np.min(input_data, axis=tuple(range(0, len(input_data.shape) - 1)))
        max_range = np.max(input_data,axis=tuple(range(0, len(input_data.shape) - 1)))
        result = tf.quantization.quantize(input_data,min_range,max_range,tf.quint8,axis=len(input_data.shape)-1)
        b = time.time()
        time_cost.append(b-a)
    print(np.around(np.average(time_cost),3))


